package br.com.aquinoevasconcelos.servlets.cliente;

import java.io.IOException;


import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.aquinoevasconcelos.fachada.Fachada;
import br.com.aquinoevasconcelos.user.UsuarioCliente;

/**
 * Servlet implementation class RemoverCliente
 */
@WebServlet("/RemoverCliente")
public class RemoverCliente extends HttpServlet {
	private static final long serialVersionUID = 1L;

	
    public RemoverCliente() {
        super();

    }

    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    	
    	
		Fachada fachada = Fachada.getInstancia();
		UsuarioCliente cliente = new UsuarioCliente();


		try {

			cliente.setId(Long.parseLong(request.getParameter("id")));

			fachada.removerCliente(cliente);
			response.sendRedirect("ListaCliente?msg=deletado");

		} catch (Exception e) {

			response.sendRedirect("pagina_erro/erro.jsp");
		}
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		service(request, response);

	}

}
